home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-06-25 | 6.7 KB | 279 lines | [TEXT/MPS ] |
- ;----------------------------------------------------------------
- ;
- ; TSMHelper.a
- ; ©1993-94 CE Software - All Rights Reserved
- ; Written by Donald Brown
- ;
- ; A small utility to properly catch clicks over TSM windows.
- ;
- ;-----------------------------------------------------------------
- BLANKS ON
- STRING ASIS
- PRINT OFF
- INCLUDE 'QuickEqu.a'
- INCLUDE 'ToolEqu.a'
- INCLUDE 'SysEqu.a'
- INCLUDE 'Traps.a'
- PRINT ON
-
- HelperStuff main export
-
- ;
- ; Procedure Install; external;
- ; installs the patches in system heap
- ;
- InitEntry BRA Install
-
- StartofInit
-
- ;
- ; MyGetNextEvent. Calls our routines, also checks mousedowns where appropriate
- ;
- MyGetNextEvent
- link A6,#0
- movem.l A1-A4/D6-D7,-(SP)
- move.l 8(A6),A4 ;temporarily keep pointer to event in A4
-
- move.w 14(A6),-(SP)
- move.w 12(A6),-(SP)
- move.l 8(A6),-(SP)
- move.l OldGetNextEvent,A1 ;call the real GetNextEvent
- jsr (A1)
- move.w (SP)+,14(A6)
-
- @DontChangeMe
- lea TheHandlers,A3 ;go through our list of handlers
- moveq #9,D7
- @HandlerLoop
- tst.l (A3) ;is there a pointer to a windowpointer?
- beq.s @NextHandler
- move.l (A3),A0 ;is there a window there?
- tst.l (A0)
- beq.s @NextHandler
-
- move.w (A4),D0 ;is it a mousedown?
- cmp.w #1,D0
- bne.s @CallHandler
- clr.b -(SP) ;see if the point is in the structure region
- move.l (A0),A0
- move.l evtMouse(A4),-(SP) ;pass the point passed to us
- move.l 114(A0),-(SP) ;pass the structure region (offset from Think Ref)
- _PtInRgn
- tst.b (SP)+
- beq.s @NextHandler
- @Callhandler
- clr.w -(SP)
- move.w 14(A6),-(SP)
- move.l A4,-(SP)
- move.l 4(A3),A0 ;call this handler
- jsr (A0) ;syntax is Function MyHandler(oldresult:integer; VAR theevent:eventrecord):integer;
- move.w (SP)+,14(A6)
- @NextHandler
- adda.l #8,A3 ;try next
- dbra D7,@HandlerLoop
-
- movem.l (SP)+,A1-A4/D6-D7
- unlk A6
- move.l (SP)+,A0
- adda.l #6,SP
- jmp (A0)
- ;
- ; MyFindWindow. If it's over one of our windows, make it a system click!
- ;
- MyFindWindow
- link A6,#0
- movem.l A1-A4/D6-D7,-(SP)
- lea TheHandlers,A3 ;go through our list of handlers
- moveq #9,D7
- @HandlerLoop
- tst.l (A3) ;is there a pointer to a windowpointer?
- beq.s @NextHandler
- move.l (A3),A0 ;is there a window there?
- tst.l (A0)
- beq.s @NextHandler
-
- clr.b -(SP) ;see if the point is in the structure region
- move.l (A0),A0
- move.l 12(A6),-(SP) ;pass the point passed to us
- move.l 114(A0),-(SP) ;pass the structure region (offset from Think Ref)
- _PtInRgn
- tst.b (SP)+
- bne.s @ItIsUs
- @NextHandler
- adda.l #8,A3 ;try next
- dbra D7,@HandlerLoop
-
- movem.l (SP)+,A1-A4/D6-D7 ;call the real FindWindow
- unlk A6
- move.l OldFindWindow,A1 ;call the real FindWindow
- jmp (A1)
-
- @ItIsUs lea LastMouse,A0 ;save the point
- move.l 12(A6),(A0)+
- move.l 4(A3),(A0)+ ;and the handler address
-
- move.l (A3),A0 ;Finally, return the proper window
- move.l 8(A6),A1
- move.l (A0),(A1)
- move.w #2,16(SP) ;Force "InSysWindow"
- movem.l (SP)+,A1-A4/D6-D7
- unlk A6
- move.l (SP)+,A0
- adda.l #8,SP
- jmp (A0)
- ;
- ; MySystemClick. If it's what we forced to be a system click
- ;
- MySystemClick
- link A6,#0
- movem.l A1-A4/D6-D7,-(SP)
- move.l 12(A6),A0 ;is it our last click?
- move.l evtMouse(A0),D0
- cmp.l LastMouse,D0
- beq.s @ItIsUs
-
- movem.l (SP)+,A1-A4/D6-D7 ;call the real SystemClick
- unlk A6
- move.l OldSystemClick,A1 ;call the real SystemClick
- jmp (A1)
- @ItIsUs
- clr.w -(SP) ;call our old handler
- clr.w -(SP) ;pass zero for old result
- move.l 12(A6),-(SP)
- move.l LastHandler,A0 ;call this handler
- jsr (A0) ;syntax is Function MyHandler(oldresult:integer; VAR theevent:eventrecord):integer;
- move.w (SP)+,D0
-
- movem.l (SP)+,A1-A4/D6-D7
- unlk A6
- move.l (SP)+,A0
- adda.l #8,SP
- jmp (A0)
- ;
- ; Procedure InstallOne(VAR wp:WindowPtr; whereproc:procptr; DoInstall:integer);
- ; DoInstall=0 for remove, non-zero to add
- ;
- InstallOne
- link A6,#0
- movem.l A3/D5-D7,-(SP)
- tst.w 8(A6) ;are we installing?
- bne.s @DoAdd
- lea TheHandlers,A3 ;go through our list of handlers
- moveq #9,D7
- @RemoveLoop
- move.l (A3),D0 ;see if this is our windowpointer
- sub.l 14(A6),D0 ;(compare the windowpointers)
- _StripAddress
- tst.l D0
- bne.s @NextRemove
- clr.l (A3) ;got it, wipe it out, we're done!
- clr.l 4(A3)
- bra.s @AllDone
- @NextRemove
- adda.l #8,A3 ;try next
- dbra D7,@RemoveLoop
- bra.s @AllDone
-
- @DoAdd
- lea TheHandlers,A3 ;go through our list of handlers
- moveq #9,D7
- @AddLoop
- tst.l (A3)
- bne.s @NextAdd ;is this an empty spot?
- move.l 14(A6),(A3) ;yup, copy us in
- move.l 10(A6),4(A3)
- bra.s @AllDone
- @NextAdd
- adda.l #8,A3 ;try next
- dbra D7,@AddLoop
-
- @AllDone
- movem.l (SP)+,A3/D5-D7
- unlk a6
- move.l (SP)+,A0
- adda.l #10,SP
- jmp (A0)
- ;
- ; The routine Gestalt will call to tell where my install routines are
- ;
- ReturnRegister
- link A6,#0
- move.l 8(A6),A0 ;return the proper response
- lea InstallOne,A1
- move.l A1,(A0)
- clr.w 16(A6)
- unlk A6
- move.l (SP)+,A0
- adda.l #8,SP
- jmp (A0)
-
- OldGetOSEvent dc.L 0 ;address of real GetOSEvent
- OldGetNextEvent dc.l 0 ;address of prior GetNextEvent
- OldFindWindow dc.L 0 ;address of real FindWindow
- OldSystemClick dc.l 0 ;address of prior SystemClick
- ;
- MyTempWindow dc.l 0 ;just used to call FindServiceWindow
- ;
- TheHandlers dcb.b 80,0 ;The registered TSM handlers
- ; array[1..10] of Record wp:WindowHandle; proc:procptr end;
- LastMouse dc.l 0 ;Location of last mouse found by findwindow
- LastHandler dc.l 0 ;and handler for it
- ;
- Install link A6,#-128
- movem.l D0-D1/A0-A4,-(SP)
- btst #0,KeyMap+7 ;see if shift key's down
- bne @999 ;if so, don't install
- ;
- ; Check on our gestalt being there!
- ;
- move.l #'tsmH',D0 ;call gestalt with our connection
- _Gestalt
- tst.w D0
- beq @999 ;if no error, we're already installed somewhere else
-
- move.W #$170,D0 ;First, save old loc of GetNextEvent
- _GetTrapAddress ,NEWTOOL
- LEA OldGetNextEvent,A1
- move.L A0,(A1)
-
- move.W #$1B3,D0 ;Next, save old loc of SystemClick
- _GetTrapAddress ,NEWTOOL
- LEA OldSystemClick,A1
- move.L A0,(A1)
-
- move.W #$12C,D0 ;Next, save old loc of FindWindow
- _GetTrapAddress ,NEWTOOL
- LEA OldFindWindow,A1
- move.L A0,(A1)
-
- move.L #Install-StartofInit,D0
- _NewPtr ,SYS ;get a block in the system heap
- move.L A0,A4 ;save the pointer
- move.L A0,A1 ;copy stuff over
- LEA StartofInit,A0
- move.L #Install-StartofInit,D0
- _BlockMove
-
- move.w #$170,D0 ;patch GetNextEvent
- LEA MyGetNextEvent-StartofInit(A4),A0
- _SetTrapAddress ,NEWTOOL
-
- move.w #$1B3,D0 ;patch SystemClick
- LEA MySystemClick-StartofInit(A4),A0
- _SetTrapAddress ,NEWTOOL
-
- move.w #$12C,D0 ;patch FindWindow
- LEA MyFindWindow-StartofInit(A4),A0
- _SetTrapAddress ,NEWTOOL
-
- move.l #'tsmH',D0 ;register us so others can find us
- LEA ReturnRegister-StartofInit(A4),A0
- _NewGestalt
- @998
-
- @999 movem.l (SP)+,D0-D1/A0-A4
- unlk A6
- RTS
-
- end
-